#include <stdio.h>

void test(int n);
void test2(int *p);
void swap(int *a, int *b);
void min_max_array(int *p, int n, int *max, int *min);

int main(void)
{
    int n = 10;

    int *p = NULL;
    int a, b;
    int arr[] = {1, 3, 5, 3, 6, 7, 1, 4};
    int max_value, min_value;
    
    test(n);

    printf("test: %d\n", n);

    p = &n;
    test2(p);

    printf("test2: %d\n", n);

    a = 3;
    b = 8;
    printf("a, b: %d %d\n", a, b);
    swap(&a, &b);
    printf("swap: %d %d\n", a, b);


    min_max_array(arr, sizeof(arr) / sizeof(int), &max_value, &min_value);
    printf("max = %d\n", max_value);
    printf("min = %d\n", min_value);
    
    
    return 0;
}


void test(int n)
{
    n = 20;
}

void test2(int *p)
{
    *p = 100;
}


void swap(int *a, int *b) 
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

/* 通过参数返回值，这种方式称为回填
 * *max 和 *min 为回填数据 
 */
void min_max_array(int *p, int n, int *max, int *min)
{
    int i;
    *max = p[0];
    *min = p[0];

    for (i = 0; i < n; i++) {
        *max = p[i] > *max ? p[i] : *max;
        *min = p[i] < *min ? p[i] : *min;
    }
}


